#include <bits/stdc++.h>
using namespace std;

typedef pair<int, int> substr_idx;

int  main() {
    string str, charset;
    cin >> str >> charset;

    vector<substr_idx> substr_vecs;
    map<char, int> char_map;
    // initial window
    int left, right;
    left = right = 0;

    // initial map
    for (auto ch:charset) {
        char_map[ch] = 0;
    }

    bool exist_ch_set;
    for (;right < str.length(); ++right) {
        exist_ch_set = true;
        if (char_map.find(str[right]) != char_map.end()) {
            char_map[str[right]]++;
            
        }
        for (auto it:char_map) {
            if (it.second == 0) {
                exist_ch_set = false;
                break;
            }
        }
        if (exist_ch_set) {
            while(exist_ch_set) {
                substr_vecs.push_back(substr_idx(left, right));
                left++;
                if (char_map.find(str[left-1]) != char_map.end()) {
                    char_map[str[left-1]]--;
                }
                for (auto it:char_map) {
                    if (it.second == 0) {
                        exist_ch_set = false;
                        break;
                    }
                }
            }
            
        }
    }
    sort(substr_vecs.begin(), substr_vecs.end(), [](substr_idx& a, substr_idx& b){
        return (a.second-a.first) < (b.second-b.first);
    });
    cout << str.substr(substr_vecs.front().first, substr_vecs.front().second-substr_vecs.front().first+1);
}